Skip to content

refactor: remove unsafe assertions from charts, addresses, and invoices - #104927

Open
KJ21-ENG wants to merge 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261023-804bc132-run-1-284f64d4
Open

KJ21-ENG wants to merge 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261023-804bc132-run-1-284f64d4

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Remove unsafe type assertions from chart filters, address defaults, country localization, and invoice company-size forwarding. Preserve exact-merchant filters, inclusive date bounds, address-field retention and validation, localization fallbacks, and current and legacy company-size values. Chart drill-down takes its filter from the chart's grouping, as on main. In a time chart, a row from another grouping adds no filter instead of throwing.

Changed files:

  • src/components/AddressForm.tsx
  • src/components/CountrySelector.tsx
  • src/components/Search/SearchChartView.tsx
  • src/components/Search/chartGroupByConfig.ts
  • src/languages/IntlStore.ts
  • src/libs/CountryUtils.ts
  • src/libs/Localize/index.ts
  • src/libs/actions/IOU/PayMoneyRequest.ts
  • src/pages/AddressPage.tsx
  • src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx
  • src/types/onyx/IntroSelected.ts
  • tests/actions/IOUTest/PayMoneyRequestTest.ts
  • tests/ui/AddressPageTest.tsx
  • tests/ui/WorkspaceTravelAddressCountryTest.tsx
  • tests/unit/CountryUtils.test.ts
  • tests/unit/Search/chartGroupByConfigTest.ts

Fixed Issues

$ #94739
PROPOSAL: #94739 (comment)

Tests

Use the candidate App against its supported test backend, signed in with a non-delegate account. Run each case on Android native, Android mWeb Chrome, iOS native, iOS mWeb Safari, macOS Chrome, and macOS Safari; use the repository's Mobile-Expensify setup for native builds. Create data through the normal App UI and check for unexpected JavaScript console errors throughout.

Country label follows the language

Setup: Save English on the Language screen in Settings > Preferences > Language. Open the signed-in App link /settings/profile/address and save 123 Main St, Suite 4, New York, United States, state New York (NY), ZIP 10001.

  1. Open /settings/profile/address. Country reads United States.
  2. Save Spanish on the Language screen. The selected App language is Spanish.
  3. Open /settings/profile/address. Country reads Estados Unidos de América and address labels are Spanish.
  4. Open the Country picker. The saved US selection is represented in the translated picker without a missing-key label or crash.
  5. Return without selecting another country. The translated US country and saved address are retained.

Personal address validation and retained fields

Setup: Save English on the Language screen and retain the US address saved in the preceding case.

  1. Open /settings/profile/address. Both street lines, New York city/state, United States and 10001 appear.
  2. Select Canada through the Country picker. Country becomes Canada and State / Province clears; city New York, ZIP 10001 and both street lines remain.
  3. Press Save. The form stays open and rejects the incomplete Canadian address; invalid state/postcode is reported.
  4. Enter Ontario in State / Province. Ontario appears without clearing city New York or the ZIP.
  5. Replace ZIP / Postcode with M5V 2T6. The edited postal code appears and city New York remains.
  6. Press Save at least one second after the rejected save. The valid Canadian address is accepted and the form closes.
  7. Reopen /settings/profile/address. Canada, Ontario, New York, M5V 2T6 and both original street lines appear.

Chart setup: create ordinary cash expenses through Create expense > Manual with different amounts: merchant I on 2023-12-31, merchant I shop on 2024-01-06, and merchant I shop on 2024-01-07. Open Expenses/Search with a date range containing all three and a supported additional filter that includes them. Restore this original result before each Bar or Line variation because drill-down removes the grouping and chart view.

Merchant bar selects the exact merchant

Setup: Restore the original Expenses/Search result described above before configuring this chart.

  1. Set Display > Group by to Merchant. I and I shop appear as distinct groups with their matching amounts.
  2. Set View to Bar. Both groups are represented in the bar chart.
  3. Press the I bar. A table opens containing only exact merchant I, excludes I shop, preserves other filters and matches the selected group amount.

Week line uses inclusive date bounds

Setup: Restore the original Expenses/Search result described above before configuring this chart.

  1. Set Display > Group by to Week. The Dec 31-Jan 6 week and Jan 7 following week appear separately.
  2. Set View to Line. Both weekly points appear in the Line chart.
  3. Press the Dec 31-Jan 6 point. A table includes the Dec 31 and Jan 6 expenses, excludes the Jan 7 control, retains other filters and leaves the grouped chart view.

Focused lint, formatting, TypeScript, React Compiler checks, and nine Jest suites (231 tests) passed on this merged head. CI passed typecheck, lint, formatting, React Compiler checks, and the selected Jest suites.

The checked-in tests cover chart dispatch and comparison-series data, country/localization fallbacks, address values including the Travel consumer, and invoice company-size forwarding. To repeat the selected suites with the normal repository test command:

npm test -- --runInBand --runTestsByPath \
  tests/unit/Search/chartGroupByConfigTest.ts \
  tests/unit/buildChartSeriesTest.ts \
  tests/unit/buildInsightsChartCSVTest.ts \
  tests/unit/getInProgressBucketLabelTest.ts \
  tests/unit/CountryUtils.test.ts \
  tests/ui/AddressPageTest.tsx \
  tests/ui/WorkspaceTravelAddressCountryTest.tsx \
  tests/actions/IOUTest/PayMoneyRequestTest.ts \
  tests/unit/OnboardingFlowTest.ts
  • Verify that no errors appear in the JS console

Offline tests

N/A. Address writes, synchronization, recovery, chart fetching, and the existing localization cache behavior are unchanged, so this refactor introduces no distinct offline case.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Screenshots/Videos (10)

Personal address desktop

104927-c01d.mp4

Personal address phone-sized

104927-c01m.mp4

Country label desktop

104927-c02d.mp4

Country label phone-sized

104927-c02m.mp4

Merchant bar desktop

104927-c03d.mp4

Merchant bar phone-sized

104927-c03m.mp4

Merchant pie desktop (extra evidence, no matching case)

104927-c04d.mp4

Merchant pie phone-sized (extra evidence, no matching case)

104927-c04m.mp4

Week line desktop

104927-c05d.mp4

Week line phone-sized

104927-c05m.mp4

Seatbelt-Operation: 0e9ad28d-53d1-4aa9-baac-7c8c97723582
@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/AddressForm.tsx 92.37% <100.00%> (+0.91%) ⬆️
src/components/CountrySelector.tsx 96.55% <100.00%> (+3.44%) ⬆️
src/components/Search/SearchChartView.tsx 91.13% <100.00%> (ø)
src/components/Search/chartGroupByConfig.ts 100.00% <100.00%> (+66.66%) ⬆️
src/libs/CountryUtils.ts 94.11% <100.00%> (ø)
src/libs/Localize/index.ts 74.62% <100.00%> (+1.61%) ⬆️
src/libs/actions/IOU/PayMoneyRequest.ts 92.48% <ø> (+10.32%) ⬆️
src/pages/AddressPage.tsx 92.85% <ø> (+17.85%) ⬆️
...gs/Profile/PersonalDetails/PersonalAddressPage.tsx 95.00% <100.00%> (+25.00%) ⬆️
... and 12 files with indirect coverage changes

Seatbelt-Operation: 9c3ccfa2-8f76-4f56-9b19-48906f453380
@KJ21-ENG KJ21-ENG changed the title Remove unsafe type assertions from charts, addresses, and invoice payments refactor: remove unsafe assertions from charts, addresses, and invoices Oct 24, 2026
Seatbelt-Operation: main-20261031-104920s-104927-sign-632c4f6a-7313-4b8a-9f85-9b67556cd2a0
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review November 2, 2026 11:23
@KJ21-ENG
KJ21-ENG requested review from a team as code owners November 2, 2026 11:23
@melvin-bot
melvin-bot Bot requested review from heyjennahay and situchan and removed request for a team November 2, 2026 11:24
@melvin-bot

melvin-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team November 2, 2026 11:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T11:44:00.801406Z 04a4e9e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant